package com.basker.pisces.concurrent.config;

import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.basker.pisces.concurrent.collection.IConcurrentCollectionManager;
import com.basker.pisces.config.Constants;
import com.basker.pisces.redis.concurrent.collection.RedissonCollectionManager;

@Configuration
@ConditionalOnClass(RedissonClient.class)
public class RedisConcurrentCollectionManagerConfiguration {
    public static final String DEFAULT_CONCURRENT_COLLECTION_MANAGER = Constants.DEFAULT_CONCURRENT_COLLECTION_MANAGER;

    /**
     * 如果当前存在配置redishost的属性，则默认缓存管理器为{@link RedissonCollectionManager}
     *
     * @param redissonClient
     * @return
     */
    @Bean(name = DEFAULT_CONCURRENT_COLLECTION_MANAGER)
    @Primary
    @ConditionalOnClass(RedissonClient.class)
    public IConcurrentCollectionManager redisssonCollectionManager(RedissonClient redissonClient) {
        return new RedissonCollectionManager(DEFAULT_CONCURRENT_COLLECTION_MANAGER, redissonClient);
    }

}
